import java.util.ArrayList;

public class Basilisk extends Piece {
	/*
	 * 8   - - - - - - - - - - - -    
	 * 7   - - - - - - - - - - - -    
	 * 6   - - - - - - - - - - - -    
	 * 5   - - - - - - - - - - - -    
	 * 4   - - - - - f - - - - - -      EARTH (2)
	 * 3   - - - - - - - - - - - -    
	 * 2   - - - - - - - - - - - -    
	 * 1   - - - - - - - - - - - - 
	 *     a b c d e f g h i j k l
	 *
	 * 8   - - - - - - - - - - - -    
	 * 7   - - - - - - - - - - - -    
	 * 6   - - - - - - - - - - - -    
	 * 5   - - - - x x x - - - - -    
	 * 4   - - - - - B - - - - - -      UNDER (3)
	 * 3   - - - - - m - - - - - -    
	 * 2   - - - - - - - - - - - -    
	 * 1   - - - - - - - - - - - -    
	 * 	   a b c d e f g h i j k l
	 * 
	 * Basilisk starts on the UnderBoard, and has the unique ability to freeze pieces
	 * on the EarthBoard. It can move or capture to any square one ahead of it, and
	 * can move one square directly back.
	 */
	
	public Basilisk(int s) {
		super(s);
	}

	protected ArrayList<Square> getAvailableMoves() {
		moves.clear();
		moves.add(getSquare().getFarSquare((getSide() * 180) % 360, 1));
		System.out.println(moves);
		return moves;
	}
	
	protected ArrayList<Square> getAvailableCapts() {
		capts.clear();
		capts.add(getSquare().getFarSquare(((getSide() - 1) * 180 + 315) % 360, 1));
		capts.add(getSquare().getFarSquare((getSide() - 1) * 180, 1));
		capts.add(getSquare().getFarSquare((getSide() - 1 * 180 + 45), 1));
		return capts;
	}
	
	@Override
	public boolean moveTo(Square dest) {
		if(canMoveTo(dest)) {
			if(getSquare().getFarSquare(Square.UP, 1).isOccupied()) {
				getSquare().getFarSquare(Square.UP, 1).getPiece().unfreeze();
			}
			setSquare(dest);
			//INSERT MOVING CODE HERE...
			if(getSquare().getFarSquare(Square.UP, 1).getPiece().getSide() != getSide()) {
				getSquare().getFarSquare(Square.UP, 1).getPiece().freeze();
			}
			return true;
		}
		return false;
	}
	
	@Override
	public boolean captTo(Square dest) {
		if(canCaptTo(dest)) {
			if(getSquare().getFarSquare(Square.UP, 1).isOccupied()) {
				getSquare().getFarSquare(Square.UP, 1).getPiece().unfreeze();
			}
			setSquare(dest);
			//INSERT MOVING CODE HERE...
			if(getSquare().getFarSquare(Square.UP, 1).getPiece().getSide() != getSide()) {
				getSquare().getFarSquare(Square.UP, 1).getPiece().freeze();
			}
			return true;
		}
		return false;
	}
	
	public String toString() {
		if(side == 1) {
			return "B";
		} else if(side == 2) {
			return "b";
		} else {
			return "no side";
		}
	}
}
